import config from '@/config/config.js';
import http from '@/api/http.js'
import axios from "axios";

let qualityRequest = {
    loadDefectlist(callBack) {
        // 获取token
        let url = config.qualityBaseUrl + "/defect/list"
        // 发送请求
        axios.get(url)
            .then(res => {
                callBack(res.data);
            })
    }, insert(defect, callBack) {
        let url = config.qualityBaseUrl + "/defect/insert"
        axios.post(url, defect)
            .then(res => {
                callBack(res.data)
            })
    }, deleteDefect(defectId, callBack) {
        let url = config.qualityBaseUrl + "/defect/deleteById?defectId=" + defectId
        axios.delete(url)
            .then(res => {
                callBack(res.data)
            })
    }, deleteDefects(defectIds, callBack) {
        let url = config.qualityBaseUrl + "/defect/deleteByIds?a=1";
        if (defectIds) {
            defectIds.forEach(defectId => url += "&defectId=" + defectId)
            // axios.delete(url)
            //     .then(res => callBack(res.data))
        }
        axios.delete(url, defectIds)
            .then(res => callBack(res.data))
    }, loadDetectlist(callBack) {
        // 获取token
        let url = config.qualityBaseUrl + "/detect/detectList"
        // 发送请求
        axios.get(url)
            .then(res => {
                callBack(res.data);
            })
    }, insertDetect(detect, callBack) {
        let url = config.qualityBaseUrl + "/detect/insert"
        axios.post(url, detect)
            .then(res => {
                callBack(res.data)
            })
    }, editDetect(detect, callBack) {
        if (detect) {
            let url = config.qualityBaseUrl + "/detect/update";
            axios.put(url, detect)
                .then(res => {
                    callBack(res.data)
                })
        }
    }, getById(detectId, callBack) {
        axios.get(config.qualityBaseUrl + "/detect/getDetectById?detectId=" + detectId)
            .then(res => callBack(res.data));
    }, deleteDetect(detectId, callBack) {
        let url = config.qualityBaseUrl + "/detect/deleteById?detectId=" + detectId
        axios.delete(url)
            .then(res => {
                callBack(res.data)
            })
    }, deleteDetects(detectIds, callBack) {
        let url = config.qualityBaseUrl + "/detect/deleteByIds?a=1";
        if (detectIds) {
            detectIds.forEach(detectId => url += "&detectId=" + detectId)
        }
        axios.delete(url, detectIds)
            .then(res => callBack(res.data))
    }, loadModellist(callBack) {
        // 获取token
        let url = config.qualityBaseUrl + "/model/list"
        // 发送请求
        axios.get(url)
            .then(res => {
                callBack(res.data);
            })
    }, deleteModel(modelId, callBack) {
        let url = config.qualityBaseUrl + "/model/deleteById?modelId=" + modelId
        axios.delete(url)
            .then(res => {
                callBack(res.data)
            })
    },getModelById(modelId, callBack) {
        axios.get(config.qualityBaseUrl + "/model/getModelById?modelId=" + modelId)
            .then(res => callBack(res.data));
    }, insertModel(model, callBack) {
        let url = config.qualityBaseUrl + "/model/insert"
        axios.post(url, model)
            .then(res => {
                callBack(res.data)
            })
    },editModel(model, callBack) {
        if (model) {
            let url = config.qualityBaseUrl + "/model/update";
            axios.put(url, model)
                .then(res => {
                    callBack(res.data)
                })
        }
    },loadModelDetectList(callBack) {
        // 获取token
        let url = config.qualityBaseUrl + "/model/detectList"
        // 发送请求
        axios.get(url)
            .then(res => {
                callBack(res.data);
            })
    }, updateDetectionById(detect, callBack) {
        if (detect) {
            let url = config.qualityBaseUrl + "/model/updateDetectionById";
            axios.put(url, detect)
                .then(res => {
                    callBack(res.data)
                })
        }
    }, deleteModelDetectionById(detectId, callBack) {
        let url = config.qualityBaseUrl + "/model/deleteModelDetectionById?detectId=" + detectId
        axios.delete(url)
            .then(res => {
                callBack(res.data)
            })
    },getModelDetectById(detectId, callBack) {
        axios.get(config.qualityBaseUrl + "/model/getModelDetectById?detectId=" + detectId)
            .then(res => callBack(res.data));
    },insertNewModelDetection(detect, callBack) {
        let url = config.qualityBaseUrl + "/model/insertNewModelDetection"
        axios.post(url, detect)
            .then(res => {
                callBack(res.data)
            })
    }
}

export default qualityRequest;